<template>
    <div>
        <h1 class="center">sending...</h1>
    </div>
</template>
<script>
import {posttwitter} from "../../../api/api"
export default{
    data(){
        return{
        }
    },
    mounted() {
        this.postTwitter();
    },
    methods:{
        postTwitter(){
            let oauth_verifier=localStorage.getItem('oauth_verifier')
            let oauth_uuid=localStorage.getItem('oauth_uuid')
            let oauth_goods_id=localStorage.getItem('oauth_goods_id')
            posttwitter({
                verifier:oauth_verifier,
                goods_id:oauth_goods_id,
                uuid:oauth_uuid
            }).then(()=>{
                localStorage.removeItem("oauth_goods_id")
                localStorage.removeItem("oauth_verifier")
                localStorage.removeItem("oauth_uuid")
                this.$message({
                    message:'Posted to twitter successfully',
                    type: 'success'
                })
                setTimeout(()=>{
                    this.$router.push({
                        name: "index", 
                    });
                },2000)
            }).catch(()=>{
                localStorage.removeItem("oauth_goods_id")
                localStorage.removeItem("oauth_verifier")
                localStorage.removeItem("oauth_uuid")
                this.$message({
                    message:'Failed to post to twitter, please try again',
                    type: 'error'
                })
                setTimeout(()=>{
                    this.$router.push({
                        name: "index", 
                    });
                },2000)
            })
            
        }
    }
}
</script>

<style scoped lang="scss">
.center{
  display: flex;
  justify-content: center;
  align-items: center; 
  width: 100%;
  height: 750px;
  font-size: 25px;
  color:rgb(5, 105, 13) ;
 }

</style>